package lab03;
import java.io.IOException;
import java.sql.*;
public class TopPassword {
    private static final String SQL = "SELECT password  ,count(*)  from db_csdn.csdn GROUP BY password ORDER BY count(*) desc limit 10";

    public static void main(String[] args) throws SQLException, IOException {DatabaseMetaData DBCPDatasource = null;
        Connection connection = DBCPDatasource.getConnection();

        PreparedStatement preparedStatement = connection.prepareStatement(SQL);


        //
        long starTime = System.currentTimeMillis();
        ResultSet resultSet = preparedStatement.executeQuery(SQL);
        System.out.println("密码"+"\t\t\t\t\t"+"数量");

        while (resultSet.next()){

            String password = resultSet.getString("password");
            String count = resultSet.getString("count(*)");
            System.out.println(password+"\t\t\t\t"+count);

        }

        long endTime = System.currentTimeMillis();
        resultSet.close();
        preparedStatement.close();
        connection.close();
        System.out.println("共耗时"+(endTime-starTime)+"ms.");
    }
}
